//
//  TestTableViewCell.m
//  10-CustomTableViewCell
//
//  Created by dllo on 16/7/27.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "TestTableViewCell.h"
#import "UIView+Frame.h"
#import "NewsObject.h"
//使用class声明的类，需要在.mach_m中去import

@interface TestTableViewCell ()
//不要和系统的控件重名




@end

@implementation TestTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.imageView1 = [[UIImageView alloc] initWithFrame:CGRectZero];
        self.label1 = [[UILabel alloc] initWithFrame:CGRectZero];
        self.label2 = [[UILabel alloc] initWithFrame:CGRectZero];
        self.label3 = [[UILabel alloc] initWithFrame:CGRectZero];
        
        
        [self.contentView addSubview:self.imageView1];
        [self.contentView addSubview:self.label1];
        [self.contentView addSubview:_label2];
//        [self.contentView addSubview:_label3];//label上不要加视图
//        _imageView1.backgroundColor = [UIColor redColor];
//        _label1.backgroundColor = [UIColor whiteColor];
//        _label2.backgroundColor = [UIColor whiteColor];
//        _label3.backgroundColor = [UIColor greenColor];
    }
    return self;
    
}

//有内容/坐标改变时，会触发该方法
- (void)layoutSubviews
{
    CGFloat leftMargin = 5;
    CGFloat topMargin = 5;
    CGFloat rightMargin = 5;
    
    [super layoutSubviews];
    _imageView1.frame = CGRectMake(5, 5, self.contentView.sy_width / 4, self.contentView.sy_height - 10);
    
//    CGFloat
    CGFloat _label1x = _imageView1.sy_x + _imageView1.sy_width + 5;
    _label1.frame = CGRectMake(_label1x, 5, self.contentView.sy_width - _label1x - 5, 30);
//    CGFloat _label2y =
    _label2.frame = CGRectMake(_label1x, 5 + _label1.sy_height + 5, _label1.sy_width, self.contentView.sy_height - 10 - _label1.sy_height);
    CGFloat _label3x = _label2.sy_width * 3 / 5;
    CGFloat _label3Height = _label2.sy_height / 2;
    CGFloat _label3Width = _label2.sy_width * 2 / 5;
    
    
//    视图坐标系转换
//    判断俯视图是不是——label2
//   / if (_label3.superview == _label2) {
    CGRect rect = [_label3.superview convertRect:_label3.frame toView:self.contentView];
    _label3.frame = rect;
    _label3.frame = CGRectMake(_label3x, _label3Height, _label3Width, _label3Height);
//    [self.contentView addSubview:_label3];
        [_label2 addSubview:_label3];
//    }
}





- (void)setNewsObject:(NewsObject *)newsObject
{
    _newsObject = newsObject;
        _label1.text = newsObject.newsTitle;
    _imageView1.image = [UIImage imageNamed:newsObject.newsImage];
        _label2.text = newsObject.newsDescription;
        _label3.text = newsObject.newsNumberCount;
}


- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
